﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OOLib
{
   /// <summary>
   /// Is the main interface for a distinct text unit, i.e. the main text of a document, the text for headers and footers or for single cells of a table.
   /// </summary>
   public class SimpleText : TextRange
   {
      #region Constructors

      /// <summary>
      /// Constructor
      /// </summary>
      /// <remarks>
      /// After using this constructor, the ComObj must be set manually!
      /// </remarks>
      public SimpleText() :
         base()
      { }

      /// <summary>
      /// Constructor
      /// </summary>
      /// <param name="comObject">COM object</param>
      public SimpleText(object comObject) :
         base(comObject)
      { }

      #endregion

      #region XSimpleText

      /// <summary>
      /// Creates a new instance of a TextCursor service which can be used to travel in the given text context.
      /// </summary>
      /// <returns>Gets a new instance of a TextCursor service which can be used to travel in the given text context.</returns>
      /// <remarks>!!! Not tested !!!</remarks>
      public TextCursor CreateTextCursor()
      {
         CheckDisposed();
         return GetObjectWrapper<TextCursor>(InvokeMethod("createTextCursor"));
      }

      /// <summary>
      /// Creates a new instance of a TextCursor which is located at the specified TextRange to travel in the given text context.
      /// </summary>
      /// <param name="textPosition">Specifies the start position for the new TextCursor.</param>
      /// <returns>Returns a new instance of a TextCursor which is located at the specified TextRange to travel in the given text context.</returns>
      /// <remarks>
      /// The initial position is set to textPosition.
      /// </remarks>
      public TextCursor CreateTextCursorByRange(TextRange textPosition)
      {
         CheckDisposed();
         return GetObjectWrapper<TextCursor>(InvokeMethod("createTextCursorByRange", textPosition.ComObj));
      }

      /// <summary>
      /// Inserts a string of characters into the text.
      /// </summary>
      /// <param name="range">
      /// Specifies the position of insertion. For example, XSimpleText::createTextCursor can be used to get an XTextRange for this argument.
      /// If the parameter bAbsorb was true the text range will contain the new inserted string, otherwise the range (and it's text) will remain unchanged.
      /// </param>
      /// <param name="str">Specifies the string to insert.</param>
      /// <param name="absorb">
      /// Specifies whether the text spanned by range will be replaced. If true then the content of range will be replaced by str, 
      /// otherwise str will be inserted at the beginning of range.
      /// </param>
      /// <remarks>
      /// The string may contain the following white spaces:
      /// <list type="unordered">
      /// <item>blank</item>
      /// <item>tab</item>
      /// <item>cr (which will insert a paragraph break)</item>
      /// <item>lf (which will insert a line break)</item>
      /// </list>
      /// !!! Not tested !!!
      /// </remarks>
      public void InsertString(TextRange range, string str, bool absorb)
      {
         CheckDisposed();
         InvokeMethod("insertString", range.ComObj, str, absorb);
      }

      /// <summary>
      /// Inserts a control character (like a paragraph break or a hard space) into the text. 
      /// </summary>
      /// <param name="range">
      /// Specifies the position of insertion. For example, XSimpleText::createTextCursor can be used to get an XTextRange for this argument.
      /// If the parameter bAbsorb was true the text range will contain the new inserted string, otherwise the range (and it's text) will remain unchanged.
      /// </param>
      /// <param name="controlCharacter">ControlCharacter to insert.</param>
      /// <param name="absorb">
      /// Specifies whether the text spanned by range will be replaced. If true then the content of range will be replaced by str, 
      /// otherwise str will be inserted at the beginning of range.
      /// </param>
      /// <remarks>!!! Not tested !!!</remarks>
      public void InsertControlCharacter(TextRange range, ControlCharacter controlCharacter, bool absorb)
      {
         CheckDisposed();
         InvokeMethod("insertControlCharacter", range.ComObj, controlCharacter, absorb);
      }

      #endregion
   }
}
